rm(list=ls())
library(tidyverse)
library(estimatr)
library(texreg)

amb <- read.csv("amb_JCR.csv") # Your file path here

# Table 3 --------------------------------------

fit1 <- lm_robust(political ~ log_gdppc, fixed_effects = ~President, clusters = CCode, data = amb)
fit2 <- lm_robust(political ~ log_gdppc + prior8 + political_risk_rev, fixed_effects = ~President, clusters = CCode, data = amb)
fit3 <- lm_robust(political ~ hardship, fixed_effects = ~President, clusters = CCode, data = amb)
fit4 <- lm_robust(political ~ hardship + prior8 + political_risk_rev, fixed_effects = ~President, clusters = CCode, data = amb)
fit5 <- lm_robust(political ~ tourism_share, fixed_effects = ~President, clusters = CCode, data = amb)
fit6 <- lm_robust(political ~ tourism_share + prior8 + political_risk_rev, fixed_effects = ~President, clusters = CCode, data = amb)

texreg(l = list(fit1, fit2, fit3, fit4, fit5, fit6),
       omit.coef = c("Intercept"),
       custom.coef.names = c("Log GDP per Capita", #1
                             "POTUS Visits Last 8 Years", #2
                             "PRS Political Risk (0-100)", #3
                             "DoS Hardship (0-35)",      #4
                             "Tourism (%GDP)"), #5
       reorder.coef = c(1, 4, 5, 2, 3),
       custom.model.names = c("(1)", "(2)", "(3)", "(4)", "(5)", "(6)"),
       custom.gof.rows = list("POTUS Fixed Effecs" = c("Yes","Yes","Yes", "Yes", "Yes", "Yes")),
       custom.note = "\\item %stars; OLS estimates with robust SEs clustered at the country level.",
       caption = "Selection of Non-Career Ambassadors",
       stars = c(0.01, 0.05, 0.1),
       include.ci = FALSE,
       caption.above = T,
       include.rsquared = F, include.adjrs = F, include.rmse = F,
       fontsize = "small",
       label = "tab:amb_patronage"
)


# Table C.7 ---------------------------------------------------------------

fit7  <- lm_robust(high_skill ~ political_risk_rev + log_gdppc, fixed_effects = ~President, clusters = CCode, data = amb)
fit8  <- lm_robust(high_skill ~ political_risk_rev + log_gdppc + prior8, fixed_effects = ~President, clusters = CCode, data = amb)
fit9  <- lm_robust(high_skill ~ political_risk_rev + hardship, fixed_effects = ~President, clusters = CCode, data = amb)
fit10  <- lm_robust(high_skill ~ political_risk_rev + hardship + prior8, fixed_effects = ~President, clusters = CCode, data = amb)
fit11  <- lm_robust(high_skill ~ political_risk_rev + tourism_share, fixed_effects = ~President, clusters = CCode, data = amb)
fit12  <- lm_robust(high_skill ~ political_risk_rev + tourism_share + prior8, fixed_effects = ~President, clusters = CCode, data = amb)

texreg(l = list(fit7, fit8, fit9, fit10, fit11, fit12),
       omit.coef = c("Intercept"),
       custom.coef.names = c("PRS Political Risk (0-100)", #1
                             "Log GDP per Capita", #2
                             "POTUS Visits Last 8 Years", #3                      
                             "DoS Hardship (0-35)", #4
                             "Tourism (% of GDP)"), #5
       reorder.coef = c(1, 2, 4, 5, 3),
       custom.model.names = c("(1)", "(2)", "(3)", "(4)", "(5)", "(6)"),
       custom.gof.rows = list("POTUS Fixed Effecs" = c("Yes","Yes","Yes", "Yes", "Yes", "Yes")),
       custom.note = "\\item %stars; OLS estimates with robust SEs clustered at the country level.",
       caption = "Selection of High-Expertise Ambassadors",
       stars = c(0.01, 0.05, 0.1),
       digits = 3,
       include.ci = FALSE,
       caption.above = T,
       include.rsquared = F, include.adjrs = F, include.rmse = F,
       fontsize = "small",
       label = "tab:ols_expertise"
)


